package com.proyecto.poo;



import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

public class TrianguloRes extends Activity {
	float base=0f;
    float altura=0f;
    float screenW,screenH,screenA;
	 /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.trianguloresult);

        
        TextView texto = (TextView)findViewById(R.id.textView1);
        
        float area=0f;
        float perimetrotrrec=0f;
        float perimetrotriso=0f;
        String restext;
        
        base=0f;
        altura=0f;
        Log.d("inicio Bundle", "BUNDLE");
        Bundle extras = getIntent().getExtras();
        if(extras !=null)
        {
         this.base = extras.getFloat("baseTriangulo");
         this.altura = extras.getFloat("alturaTriangulo");
        }
        Log.d("Valor de base", ""+base);
        Log.d("Valor de altura", ""+altura);
        Log.d("Inicio calculos ", "Area perimetro etc");
        area=(base*altura)/2;
        perimetrotrrec = (float) ((base)+(altura)+(Math.sqrt((base*base)+(altura*altura))));
        perimetrotriso= (float) ((base)+ (2*(Math.sqrt(((base/2)*(base/2))+(altura*altura)))));
       
        Log.d("Valor de perimetrotrrec", ""+perimetrotrrec);
        Log.d("Valor de perimetroiso", ""+perimetrotriso);
        
        restext="Area: "+Float.toString(area)+" Unidades\n"+"Perimetro triangulo rectangulo: "+Float.toString(perimetrotrrec)+" Unidades"+"\nPerimetro triangulo isoceles: "+Float.toString(perimetrotriso)+" Unidades";
        try{
        texto.setText(restext);
        }catch(Exception ie){}       
        
        LinearLayout linearLayout = (LinearLayout)findViewById(R.id.linearLayout1);
        Lienzo fondo=new Lienzo(this);        
        linearLayout.addView(fondo);


    }
    
    class Lienzo extends View {

        public Lienzo(Context context) {
            super(context);
        }
        
        protected void onDraw(Canvas canvas) {
            float proporcion=1;
            
        	if((base*altura)>(((canvas.getWidth()*canvas.getHeight()/2    ))))
            {
            	proporcion=(base*altura)/120000;
            }
        	
            
            Paint pincel1=new Paint();
            pincel1.setStrokeWidth(3);
            pincel1.setARGB(130,116,183,252);
            
            canvas.drawLine(5, 260, 5, 260-altura/proporcion, pincel1);//altura
            canvas.drawLine(5, 260, 5+base/proporcion, 260, pincel1);//base
            canvas.drawLine(5, 260-altura/proporcion, 5+base/proporcion, 260, pincel1);//hipo
            
            canvas.drawLine(5, 550, 5+base/proporcion, 550, pincel1);//altura
            canvas.drawLine(5, 550, 5+(base/2)/proporcion, 550-altura/proporcion, pincel1);//base
            canvas.drawLine(5+base/proporcion, 550, 5+(base/2)/proporcion, 550-altura/proporcion, pincel1);//hipo
            
          
        }
    }    

}
